﻿using UnityEngine;
using System.Collections;

public class PlayerScript : MonoBehaviour {

    [SerializeField]
    private PlayerAnimationController mAnimation;

    public void Attack()
    {
        Collider2D[] colliders = Physics2D.OverlapCircleAll(this.transform.position, 1.5f);

        for (int i = 0; i < colliders.Length; i++)
        {
            if (colliders[i].gameObject.tag != "Player")
            {
                
                Vector2 ShitftedVector =  colliders[i].transform.position - this.transform.position;

                float angle = MathHelper.AngleDifferance(new Vector2(0, 1), ShitftedVector);
                float PlayerAngle = GetAngle();
                if (angle < PlayerAngle + 45 && angle > PlayerAngle - 45)
                {
                    Debug.Log("BAM2");
                    colliders[i].gameObject.GetComponent<LizardManScript>().KnockBack(ShitftedVector.normalized);
                }
            }
        }

    }

    private float GetAngle()
    {
        switch (mAnimation.AnimationDirection)
        {
            case AnimationConst.WEST:
                return 270;
            case AnimationConst.EAST:
                return 90;
            case AnimationConst.NORTH:
                return 0;
            case AnimationConst.SOUTH:
                return 180;
            default:
                return 0;
        }

    }
}
